package top.tungsword.webconsole.controller.main;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.tungsword.webconsole.biz.param.LoginParam;
import top.tungsword.webconsole.biz.response.WebReturnInfo;
import top.tungsword.webconsole.biz.service.login.LoginBiz;
import top.tungsword.webconsole.controller.base.BaseController;
import top.tungsword.webconsole.interceptor.Authority;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author chenji.yu
 * @date 2020/4/7 19:00
 * @description
 */
@Controller
@RequestMapping("/")
public class LoginController extends BaseController {

    @Autowired
    private LoginBiz loginBiz;

    @GetMapping("/login")
    @Authority
    public String loginInit(){
        return "login";
    }

    @PostMapping(value = "/dologin")
    @Authority
    @ResponseBody
    public WebReturnInfo<String> dologin(HttpServletResponse response, LoginParam loginParam){
       return loginBiz.login(response, loginParam);
    }

    @GetMapping("/logout")
    public String logout(HttpServletRequest request, HttpServletResponse response){
        loginBiz.logout(request, response);
        return redirectTo("login");
    }
}
